***Read in Schedule 1 NSS data***


***Set this to the data directory
local rootdir 
cd "`rootdir'"



#delimit;

************************************************;
******************38th round********************;
cd "`rootdir'Round38\";

***Level 1 - household;

infix cdi 1-2 round 3 sector 4 fsu 5-9 region 10-12 subround 13 hhno 14-15 sample 16 stratum 17-18 subsample 19 segment 20-21 stuff 22-27 
adultm 28-29 adultf 30-31 child 32-33 hhsize 34-35 nic 36-38 nco 39-41 htype 42 religion 43 hgroup 44 homestead 45 land 46-51 mpce 52-59 
latrine 60 flushno 61-62 water 63 cook 64 light 65 ownhland 66 covarea 67-71 landpos 72 plinth 73 typedwell 74 typestruct 75 floortype 76 rent 77-83 
condition 84 twosq 85 recno 86-87 lastrec 88 update 89 pstratum 90-92 multcomb 93-101 multsub 102-110 using Dl0114r.dat;
keep if cdi==1;
capture: drop cdi lastrec update stuff*; 
replace land=land/100;
replace mpce=mpce/100;
replace rent=rent/100;
replace multcomb=multcomb/100;
replace multsub=multsub/100;
drop stratum;
ren pstratum stratum;
replace round=38;
save round38_level1, replace;

clear;
infix cdi 1-2 round 3 sector 4 fsu 5-9 region 10-12 subround 13 hhno 14-15 sample 16 stratum 17-18 subsample 19 segment 20-21 stuff 22-27 
adultm 28-29 adultf 30-31 child 32-33 hhsize 34-35 nic 36-38 nco 39-41 htype 42 religion 43 hgroup 44 homestead 45 land 46-51 mpce 52-59 
latrine 60 flushno 61-62 water 63 cook 64 light 65 ownhland 66 covarea 67-71 landpos 72 plinth 73 typedwell 74 typestruct 75 floortype 76 rent 77-83 
condition 84 twosq 85 recno 86-87 lastrec 88 update 89 pstratum 90-92 multcomb 93-101 multsub 102-110 using Dl0114u.dat;
keep if cdi==1;
capture: drop cdi lastrec update stuff*; 
replace land=land/100;
replace mpce=mpce/100;
replace rent=rent/100;
replace multcomb=multcomb/100;
replace multsub=multsub/100;
drop stratum;
ren pstratum stratum;
replace round=38;
append using round38_level1;
save round38_level1, replace;

***Level 2 -- more household;
# delimit ;
clear;
infix sector 1 region 2-4 stratum 5-7 subround 8 subsample 9 fsu 10-14 hhno 15-16 hgroup 17 z 18 mpce 19-26 mpcecode 27-28 hhsize 29-30 cunit 31-34
guestcermeals 35-38 guestsmeals 39-42 empmeals 43-46 fammealfree 47-49 fammealpay 50-52 fammealhome 53-55 calorie_cereal 56-63 calorie_cersub 64-71
 fgroup1 72-79 fgroup2 80-87 fgroup3 88-95 fgroup4 96-103 fgroup5 104-111 totcal 112-119 protein_cereal 120-126 protein_pulses 127-133 protein_milk 134-140
 protein_meat 141-147 totprotein 148-154 totfat 155-161 totfoodexp 162-171 totnonfoodexp 172-181 multcomb 182-190 multsub 191-199 oldhtype 200 using D200l02r.dat;
replace mpce=mpce/100;
foreach i of varlist calorie_cereal-multsub{;
replace `i'=`i'/100;
};
capture: drop stuff*;
save round38_level2, replace;

clear;
infix sector 1 region 2-4 stratum 5-7 subround 8 subsample 9 fsu 10-14 hhno 15-16 hgroup 17 z 18 mpce 19-26 mpcecode 27-28 hhsize 29-30 cunit 31-34
guestcermeals 35-38 guestsmeals 39-42 empmeals 43-46 fammealfree 47-49 fammealpay 50-52 fammealhome 53-55 calorie_cereal 56-63 calorie_cersub 64-71
fgroup1 72-79 fgroup2 80-87 fgroup3 88-95 fgroup4 96-103 fgroup5 104-111 totcal 112-119 protein_cereal 120-126 protein_pulses 127-133 protein_milk 134-140
protein_meat 141-147 totprotein 148-154 totfat 155-161 totfoodexp 162-171 totnonfoodexp 172-181 multcomb 182-190 multsub 191-199 oldhtype 200 using D200l02u.dat;
replace mpce=mpce/100;
foreach i of varlist calorie_cereal-multsub{;
replace `i'=`i'/100;
};
capture: drop stuff*;
append using round38_level2;
save round38_level2, replace;

***Level 3 -- aggregated person level data NOTE- person rosters only in the Schedule 10 file!;
# delimit ;
clear;
infix sector 1 region 2-4 stratum 5-7 subround 8 subsample 9 fsu 10-14 hhno 15-16 hgroup 17 z 18 mpce 19-26 mpcecode 27-28 hhsize 29-30
str stuff 31-68 rent 69-75 stuff2 76-80 adjmpce 81-88 rentadjmpce 89-96 stuff3 97-120 using D120l03r.dat;
replace rent=rent/100;
replace mpce=mpce/100;
replace adjmpce=adjmpce/100;
replace rentadjmpce=rentadjmpce/100;
capture: drop stuff*;
save round38_level3, replace;

clear;
infix sector 1 region 2-4 stratum 5-7 subround 8 subsample 9 fsu 10-14 hhno 15-16 hgroup 17 z 18 mpce 19-26 mpcecode 27-28 hhsize 29-30
str stuff 31-68 rent 69-75 stuff2 76-80 adjmpce 81-88 rentadjmpce 89-96 stuff3 97-120 using D120l03u.dat;
replace mpce=mpce/100;
replace rent=rent/100;
replace adjmpce=adjmpce/100;
replace rentadjmpce=rentadjmpce/100;
capture: drop stuff*;
append using round38_level3;
save round38_level3, replace;

clear;
use round38_level1;
sort sector region subsample subround fsu hhno;
save temp, replace;
clear;
use round38_level2;
sort sector region subsample subround fsu hhno;
merge sector region subsample subround fsu hhno using temp;
tab _merge;
drop _merge;
sort sector region subsample subround fsu hhno;
save temp, replace;
clear;
use round38_level3;
sort sector region subsample subround fsu hhno;
merge sector region subsample subround fsu hhno using temp;
tab _merge;
drop _merge;
sort sector region subsample subround fsu hhno;
gen substratum=1;
gen ssstratum=1;
ren segment segment_old;
gen segment=1;
save round38_chh, replace;



***Level 4,5-6,7-8,9,10-11;
foreach sector in r u{;
clear;
infix sector 1 region 2-4
stratum 5-7 subround 8 subsample 9 
fsu 10-14 hhno 15-16
str stuff 17-34
rectype 35-36
item 37-39 type 40
cashquant 41-48 cashvalue 49-56
homequant 57-64 homevalue 65-72
quant 73-80 value 81-88
str stuff2 89-110 
using D110l04`sector'.dat;

foreach j in cashquant cashvalue homequant homevalue quant value{;
replace `j'=`j'/100;
};
drop stuff*;
save r38_4`sector', replace;

clear;
infix sector 1 region 2-4
stratum 5-7 subround 8 subsample 9 
fsu 10-14 hhno 15-16
str stuff 17-34
rectype 35-36
item 37-39 type 40
cashquant 41-48 cashvalue 49-56
homequant 57-64 homevalue 65-72
quant 73-80 value 81-88
str stuff2 89-110 
using D110l56`sector'.dat;
foreach j in cashquant cashvalue homequant homevalue quant value{;
replace `j'=`j'/100;
};
drop stuff*;
save r38_56`sector', replace;

clear;
infix sector 1 region 2-4
stratum 5-7 subround 8 subsample 9 
fsu 10-14 hhno 15-16
str stuff 17-34
rectype 35-36
item 37-39 
cashquant 40-42 cashvalue 43-50
homequant 51-53 homevalue 54-61
quant 62-64 value 65-72
str stuff2 73-100
using D100L78`sector'.dat;
foreach j in cashvalue homevalue value{;
replace `j'=`j'/100;
};
drop stuff*;
save r38_78`sector', replace;

clear;
infix sector 1 region 2-4
stratum 5-7 subround 8 subsample 9 
fsu 10-14 hhno 15-16
str stuff 17-34
rectype 35-36
item 37-39 
cashvalue 40-47 value 48-55
str stuff2 56-80
using D80L09`sector'.dat;
foreach j in cashvalue value{;
replace `j'=`j'/100;
};
drop stuff*;
save r38_9`sector', replace;


clear;
infix sector 1 region 2-4
stratum 5-7 subround 8 subsample 9 
fsu 10-14 hhno 15-16
str stuff 17-34
rectype 35-36
item 37-39 
quant 40-42
firstcashvalue 43-50 firstvalue 51-58
secondcashvalue 59-66 secondvalue 67-74
str stuff2 75-100
using DL1011`sector'.dat;
foreach j in 
firstcashvalue firstvalue
secondcashvalue secondvalue{;
replace `j'=`j'/100;
};
drop stuff*;
save r38_1011`sector', replace;
};

clear;
use r38_4r;
append using r38_4u;
replace item=item-100;
keep sector region subround subsample fsu hhno item quant value homequant homevalue type;
save temp, replace;

clear;
use r38_56r;
append using r38_56u;
drop if rectype==5;
replace item=item+500;
replace quant=quant/12;
replace value=value/12;
replace homequant=homequant/12;
replace homevalue=homevalue/12;
keep sector region subround subsample fsu hhno item quant value homequant homevalue type;
append using temp;
save temp, replace;

clear;
use r38_78r;
append using r38_78u;
drop if rectype==7;
replace item=item+500;
replace quant=quant/12;
replace value=value/12;
replace homequant=homequant/12;
replace homevalue=homevalue/12;
keep sector region subround subsample fsu hhno item quant value homequant homevalue;
append using temp;
save temp, replace;

clear;
use r38_9r;
append using r38_9u;
replace item=item+500;
*replace quant=quant;
*replace value=value;
keep sector region subround subsample fsu hhno item value;
append using temp;
save temp, replace;

# delimit ;

clear;
use r38_1011r;
append using r38_1011u;
replace item=item+500;
replace firstvalue=0 if firstvalue==.;
replace secondvalue=0 if secondvalue==.;
gen value=(firstvalue+secondvalue)/12;
replace quant=quant/12;
keep sector region subround subsample fsu hhno item quant value;
append using temp;
replace quant=. if quant==0;


forvalues j=0(10)810{;
drop if item==`j';
};


forvalues j=830(10)1030{;
drop if item==`j';
};

drop if item==899;
drop if item>1050;
drop if item<0;

gen segment=1;
gen substratum=1;
gen ssstratum=1;
save round38_cedit, replace;









************************************************;
******************************43rd round********;
cd "`rootdir'Round43\";


*Level 1 - household;
clear;
infix filler 1 oldmpce 2-9 round 10-11 sch 12-14
sample 15 sector 16 fsu 17-21 region 22-24 stratum 25-26
subsample 27 samplevb 28-30 subround 31 substratum 32 
hhno 33-34 level 35-36 district 37-38 headmale 39
stuff 40-44 hhsize 45-47 nic 48-50 nco 51-53 htype 54 religion 55
hgroup 56 homestead 57 landowned 58-61 landin 62-65 landneither 66-69
landout 70-73 landpos 74-77 cultowned 78-81
cultin 82-85 cultneither 86-89 cultpos 90-93 irrigated 94-97
hiredlabor 98 hiredlabor_nonagg 99 mpce 100-107
cook 108 light 109 grow0 110 grow1 111 grow2 112 grow3 113 grow4 114
grow5 115 grow6 116 grow7 117 publicworks 118 cultivation 119
fishing 120 wage 121 nonaggent 122 pension 123 remittances 124
interest 125 others 126 irdp 127 milch 128 draught 129 ration 130
consume1 131 consume2 132 consume3 133 consume4 134 consume5 135
consume6 136 consume7 137 trainwork 138 traineduc 139 trainoth 140
buswork 141 buseduc 142 busother 143 ceremony 144
cer1 145 cer1code 146 cer1meals 147-152 
cer2 153 cer2code 154 cer2meals 155-160
cer3 161 cer3code 162 cer3meals 163-168
cer4 169 cer4code 170 cer4meals 171-176
cer5 177 cer5code 178 cer5meals 179-184
cer6 185 cer6code 186 cer6meals 187-192
cer7 193 cer7code 194 cer7meals 195-200
ownhouse 201 coverarea 202-206 landposcode 207
plinth 208 typedwell 209 typestruct 210 typefloor 211
rent 212-219 condition 220 housecat 221-222 adultm 223-224 adultf
225-226 childm 227-228 childf 229-230
mpcecode 231-232 newhtype 233 newhgroup 234 landposcode2 235
sizeclass 236 mult 237-244 cunit 245-248 agehh 249-250 using d250hhr.dat;
*land in hectaresm top-coded at 99.99;
foreach i of varlist landowned-irrigated mpce mult{;
replace `i'=`i'/100;
};
capture: drop stuff* filler*;
save round43_chh, replace;


clear;
infix filler 1 oldmpce 2-9 round 10-11 sch 12-14
sample 15 sector 16 fsu 17-21 region 22-24 stratum 25-26
subsample 27 samplevb 28-30 subround 31 substratum 32 
hhno 33-34 level 35-36 district 37-38 headmale 39
stuff 40-44 hhsize 45-47 nic 48-50 nco 51-53 htype 54 religion 55
hgroup 56 homestead 57 landowned 58-61 landin 62-65 landneither 66-69
landout 70-73 landpos 74-77 cultowned 78-81
cultin 82-85 cultneither 86-89 cultpos 90-93 irrigated 94-97
hiredlabor 98 hiredlabor_nonagg 99 mpce 100-107
cook 108 light 109 grow0 110 grow1 111 grow2 112 grow3 113 grow4 114
grow5 115 grow6 116 grow7 117 publicworks 118 cultivation 119
fishing 120 wage 121 nonaggent 122 pension 123 remittances 124
interest 125 others 126 irdp 127 milch 128 draught 129 ration 130
consume1 131 consume2 132 consume3 133 consume4 134 consume5 135
consume6 136 consume7 137 trainwork 138 traineduc 139 trainoth 140
buswork 141 buseduc 142 busother 143 ceremony 144
cer1 145 cer1code 146 cer1meals 147-152 
cer2 153 cer2code 154 cer2meals 155-160
cer3 161 cer3code 162 cer3meals 163-168
cer4 169 cer4code 170 cer4meals 171-176
cer5 177 cer5code 178 cer5meals 179-184
cer6 185 cer6code 186 cer6meals 187-192
cer7 193 cer7code 194 cer7meals 195-200
ownhouse 201 coverarea 202-206 landposcode 207
plinth 208 typedwell 209 typestruct 210 typefloor 211
rent 212-219 condition 220 housecat 221-222 adultm 223-224 adultf
225-226 childm 227-228 childf 229-230
mpcecode 231-232 newhtype 233 newhgroup 234 landposcode2 235
sizeclass 236 mult 237-244 cunit 245-248 agehh 249-250 using d250hhu.dat;
*land in hectaresm top-coded at 99.99;
foreach i of varlist landowned-irrigated mpce mult{;
replace `i'=`i'/100;
};
capture: drop stuff* filler*;
append using round43_chh;
gen segment=1;
gen ssstratum=1;
save round43_chh, replace;



*Level 2: person file;
# delimit ;
clear;
infix str stuff 1-9 round 10-11 sch 12-14
sample 15 sector 16 fsu 17-21 region 22-24 stratum 25-26
subsample 27 samplevb 28-30 subround 31 substratum 32 
hhno 33-34 level 35-36 
persno 37-39 typecode 40 relhh 41 sex 42 age 43-44 mstatus 45
genedcode 46 daysaway 47-48 meals 49 mealsfree 50-52
mealspay 53-55 mealshome 56-58 str stuff2 59-120 adultm 121-122
adultf 123-124 childm 125-126 childf 127-128 mpcecode 129-130
newhtype 131 newhgroup 132 landposcode 133 sizeclass 134
mult 135-142 cunit 143-146 agehh 147-148 filler2 149-150 mpce 151-158 filler 159-160
using Dl57-13r.dat;
keep if level==5;
replace mpce=mpce/100;
replace mult=mult/100;
drop stuff* filler*;
save round43_cpers, replace;

clear;
infix str stuff 1-9 round 10-11 sch 12-14
sample 15 sector 16 fsu 17-21 region 22-24 stratum 25-26
subsample 27 samplevb 28-30 subround 31 substratum 32 
hhno 33-34 level 35-36 
persno 37-39 typecode 40 relhh 41 sex 42 age 43-44 mstatus 45
genedcode 46 daysaway 47-48 meals 49 mealsfree 50-52
mealspay 53-55 mealshome 56-58 str stuff2 59-120 adultm 121-122
adultf 123-124 childm 125-126 childf 127-128 mpcecode 129-130
newhtype 131 newhgroup 132 landposcode 133 sizeclass 134
mult 135-142 cunit 143-146 agehh 147-148 filler2 149-150 mpce 151-158 filler 159-160
using Dl57-13u.dat;
keep if level==5;
replace mpce=mpce/100;
replace mult=mult/100;
capture: drop stuff* filler*;
append using round43_cpers;
gen segment=1;
gen ssstratum=1;
save round43_cpers, replace;


***Consumption levels;

foreach sector in r u{;
clear;


infix str stuff 1-14
sample 15 sector 16 
fsu 17-21 region 22-24
stratum 25-26 subsample 27
samplevb 28-30
subround 31 substratum 32
hhno 33-34 level 35-36
item 37-39 type 40
cashquant 41-48 cashvalue 49-56
homequant 57-64 homevalue 65-72
giftquant 73-80 giftvalue 81-88
quant 89-96 value 97-104
str stuff2 105-112 rice 113 wheat 114 jowar 115 bajra 116 maize 117 barley 118 ragi 119 gram 120 str stuff3 121-160
using D160l6`sector'.dat;
drop stuff*;
foreach j in cashquant cashvalue homequant homevalue giftquant giftvalue
quant value{;
replace `j'=`j'/100;
};
save r43_6`sector', replace;

clear;
infix str stuff 1-14
sample 15 sector 16 
fsu 17-21 region 22-24
stratum 25-26 subsample 27
samplevb 28-30
subround 31 substratum 32
hhno 33-34 level 35-36
item 37-39 type 40
cashquant 41-48 cashvalue 49-56
homequant 57-64 homevalue 65-72
giftquant 73-80 giftvalue 81-88
quant 89-96 value 97-104
str stuff2 105-160
using Dl57-13`sector'.dat;
keep if level==8 | level==10;
drop stuff*;
foreach j in cashquant cashvalue homequant homevalue giftquant giftvalue
quant value{;
replace `j'=`j'/100;
};
save r43_810`sector', replace;

clear;
infix str stuff 1-14
sample 15 sector 16 
fsu 17-21 region 22-24
stratum 25-26 subsample 27
samplevb 28-30
subround 31 substratum 32
hhno 33-34 level 35-36
item 37-39 type 40
cashvalue 41-48 value 49-56
str stuff2 57-160
using Dl57-13`sector'.dat;
keep if level==11;
drop stuff*;
foreach j in cashvalue value{;
replace `j'=`j'/100;
};
save r43_11`sector', replace;



clear;
infix str stuff 1-14
sample 15 sector 16 
fsu 17-21 region 22-24
stratum 25-26 subsample 27
samplevb 28-30
subround 31 substratum 32
hhno 33-34 level 35-36
item 37-39 type 40
number 41-44 firstquant 45-48 purchase 49
firstcashvalue 50-57 firstvalue 58-65
repaircashvalue 66-73 repairvalue 74-81
cashvalue 82-89 value 90-97 
secondquant 98-101
secondcashvalue 102-109
secondvalue 110-117
str stuff2 118-160
using Dl57-13`sector'.dat;
keep if level==13;
drop stuff*;
foreach j in firstcashvalue firstvalue
repaircashvalue repairvalue
cashvalue value
secondcashvalue secondvalue{;
replace `j'=`j'/100;
};
save r43_13`sector', replace;
};


# delimit ;

clear;
use r43_6r;
append using r43_6u;
keep sample sector fsu region stratum subsample subround substratum hhno item quant value homequant homevalue type;
replace item=item-100;
save temp, replace;

clear;
use r43_810r;
append using r43_810u;
replace value=value/12;
replace quant=quant/12;
replace homevalue=homevalue/12;
replace homequant=homequant/12;
keep sample sector fsu region stratum subsample subround substratum hhno item quant value homequant homevalue type;
replace item=item-100;
append using temp;
save temp, replace;

clear;
use r43_11r;
append using r43_11u;
keep sample sector fsu region stratum subsample subround substratum hhno item value type;
replace item=item-100;
append using temp;
save temp, replace;

clear;
use r43_13r;
append using r43_13u;
replace firstquant=0 if firstquant==.;
replace secondquant=0 if secondquant==.;
replace value=0 if value==.;
replace secondvalue=0 if secondvalue==.;
gen quant=firstquant+secondquant;
replace value=value+secondvalue;
replace quant=quant/12;
replace value=value/12;
keep sample sector fsu region stratum subsample subround substratum hhno item
quant value type;
replace item=item-100;
append using temp;

replace quant=. if quant==0;

forvalues j=9(10)559{;
drop if item==`j';
};
forvalues j=579(10)689{;
drop if item==`j';
};

*569 - taxes and cesses;

drop if item<0;
drop if item>689;
gen segment=1;
gen ssstratum=1;
save round43_cedit, replace;





****************************************;
*******************55th round************;



cd "`rootdir'Round55\";



save mult55_orig, emptyok replace;
forvalues j=1(1)4{;
infile using "D:\Dropbox\IndiaNSSData\55\dct\55mult_RU`j'.dct", clear;
keep if level==1;
keep round-fsu mult211 mult212 mult221 mult222 mult219 mult229 seg1sss1-seg2sss2;
drop sched centralstate;
cap: drop counter;
append using mult55_orig;
cap: drop counter;
duplicates drop fsu subround, force;
save mult55_orig, replace;
};






clear;
save round55_chh1, replace emptyok;
save round55_chh2, replace emptyok;
save round55_chh3, replace emptyok;
save round55_cpers, replace emptyok;


foreach sector in R U{;
forvalues round=1(1)4{;


*household records;

clear;
infix recno 1-4 round 5 sch 6-7 region 8-10
subround 11 subsample 12 flot 13-17 fsu 18-22
visit 23 segment 24 filler 25 substratum 26 hhno 27-28
level 29-30
filler2 31-35 stuff 36-41 date 42-49
stuff2 50-115
sample 116 sector 117 district 118-119 stratum 120-121
fodsubregion 122-125 update 126
using D126`sector'`round'.dat;
keep if level==1;
capture: drop stuff* filler*;
append using round55_chh1;
save round55_chh1, replace;

clear;
infix recno 1-4 round 5 sch 6-7 region 8-10
subround 11 subsample 12 flot 13-17 fsu 18-22
visit 23 segment 24 filler 25 substratum 26 hhno 27-28
level 29-30
filler2 31-35 
hhsize 36-38 nic 39-43 nco 44-46 htype 47
religion 48 hgroup 49 ownland 50 typeland 51
landowned 52-56 landin 57-61 landneither 62-66
landout 67-71 landpos 72-76
cultpos 77-81 irrigated 82-86 garden 87
cook 88-89 light 90 irop 91 publicworks 92
cultivation 93 fishing 94 wage 95 nonaggent 96
pension 97 rent 98 remittances 99 interest 100 other 101
mpce 102-107 stuff2 108-126 using D126`sector'`round'.dat;
keep if level==2;
capture: drop stuff* filler*;
append using round55_chh2;
save round55_chh2, replace;


*self-reported hunger...;
clear;
infix recno 1-4 round 5 sch 6-7 region 8-10
subround 11 subsample 12 flot 13-17 fsu 18-22
visit 23 segment 24 filler 25 substratum 26 hhno 27-28
level 29-30
filler2 31-35 twosq 36
jan 37-38
feb 39-40
mar 41-42
apr 43-44
may 45-46
jun 47-48
jul 49-50
aug 51-52
sep 53-54
oct 55-56
nov 57-58
dec 59-60
whetherasked 61
filler3 62-126
using D126`sector'`round'.dat;
keep if level==12;
capture: drop filler*;
append using round55_chh3;
save round55_chh3, replace;

****Level 3- person records;
clear;
infix recno 1-4 round 5 sch 6-7 region 8-10
subround 11 subsample 12 flot 13-17 fsu 18-22
visit 23 segment 24 filler 25 substratum 26 hhno 27-28
level 29-30
filler2 31-32 persno 33-35
relhh 36 sex 37 age 38-39 mstatus 40
generaled 41-42 worker 43 typeinc 44
daysaway 45-46 mealsday 47 mealsfree 48-49 mealsemp 50-51
mealsother 52-53 mealspay 54-55 mealshome 56-57 blank 58-115
sample 116 sector 117 district 118-119 stratum 120-121
fodsubregion 122-125 update 126
using D126`sector'`round'.dat;
keep if level==3;
capture: drop filler* blank*;
append using round55_cpers;
save round55_cpers, replace;

};
};

clear;
use round55_chh1;
sort region subround subsample fsu segment substratum hhno;
save temp, replace;
clear;
use round55_chh2;
sort region subround subsample fsu segment substratum hhno;
drop if mpce==.;
drop if htype==.;
merge region subround subsample fsu segment substratum hhno using temp;
tab _merge;
drop _merge;
sort region subround subsample fsu segment substratum hhno;
save temp, replace;
clear;
use round55_chh3;
sort region subround subsample fsu segment substratum hhno;
by region subround subsample fsu segment substratum hhno:  gen num=_n;
by region subround subsample fsu segment substratum hhno:  gen num2=_N;
foreach j in twosq jan feb mar apr may jun jul aug sep oct nov dec whetherasked{;
by region subround subsample fsu segment substratum hhno: replace `j'=`j'[_n+1] if num==1 & num2==2 & `j'==.;
by region subround subsample fsu segment substratum hhno: replace `j'=`j'[_n+2] if num==1 & num2==3 & `j'==.;
};
keep if num==1;
drop num num2;
sort region subround subsample fsu segment substratum hhno;
merge region subround subsample fsu segment substratum hhno using temp;
tab _merge;
drop _merge;
merge m:1 subround fsu using mult55_orig;
tab _merge;
keep if _merge==3;
drop _merge;
gen mult_subrnd=.;
replace mult_subrnd=mult211 if segment==1 & substratum==1;
replace mult_subrnd=mult212 if segment==1 & substratum==2;
replace mult_subrnd=mult221 if segment==2 & substratum==1;
replace mult_subrnd=mult222 if segment==2 & substratum==2;
ren mult_subrnd mult_ss;
gen ssstratum=1;
save round55_chh, replace;


******Levels 4 and up -- Consumption data;

foreach sector in r u{;

forvalues k=4(1)13{;
clear;
save r55_`k'`sector', emptyok replace;
};

forvalues k=1(1)4{;

clear;
infix str stuff 1-7
region 8-10 subround 11 subsample 12 str stuff2 13-17
fsu 18-22 visit 23 segment 24 stuff3 25 substratum 26
hhno 27-28 level 29-30 stuff4 31-32
item 33-35
quant7 36-43 value7 44-51
quant 52-59 value 60-67
source 68 str stuff5 69-126
using D126`sector'`k'.dat;
drop stuff*;
keep if level==4;
foreach j in quant7 value7 quant value{;
replace `j'=`j'/100;
};
append using r55_4`sector';
save r55_4`sector', replace;

clear;
infix str stuff 1-7
region 8-10 subround 11 subsample 12 str stuff2 13-17
fsu 18-22 visit 23 segment 24 stuff3 25 substratum 26
hhno 27-28 level 29-30 stuff4 31-32
item 33-35
quant 36-43 value 44-51 source 52
str stuff5 53-126
using D126`sector'`k'.dat;
drop stuff*;
keep if level==5;
foreach j in quant value{;
replace `j'=`j'/100;
};
append using r55_5`sector';
save r55_5`sector', replace;

clear;
infix str stuff 1-7
region 8-10 subround 11 subsample 12 str stuff2 13-17
fsu 18-22 visit 23 segment 24 stuff3 25 substratum 26
hhno 27-28 level 29-30 stuff4 31-32
item 33-35
quant 36-43 value 44-51
str stuff5 52-126
using D126`sector'`k'.dat;
drop stuff*;
keep if level==6;
foreach j in quant value{;
replace `j'=`j'/100;
};
append using r55_6`sector';
save r55_6`sector', replace;

clear;
infix str stuff 1-7
region 8-10 subround 11 subsample 12 str stuff2 13-17
fsu 18-22 visit 23 segment 24 stuff3 25 substratum 26
hhno 27-28 level 29-30 stuff4 31-32
item 33-35
value 36-43 str stuff5 44-126
using D126`sector'`k'.dat;
drop stuff*;
keep if level==7;
foreach j in value{;
replace `j'=`j'/100;
};
append using r55_7`sector';
save r55_7`sector', replace;

clear;
infix str stuff 1-7
region 8-10 subround 11 subsample 12 str stuff2 13-17
fsu 18-22 visit 23 segment 24 stuff3 25 substratum 26
hhno 27-28 level 29-30 stuff4 31-32
item 33-35
number 36-38
firstquant 39-41 purchase 42
firstvalue  43-50 repairvalue 51-58
value 59-66 secondquant 67-69
secondvalue 70-77 
str stuff5 78-126
using D126`sector'`k'.dat;
drop stuff*;
keep if level==8;
foreach j in firstvalue repairvalue value secondvalue{;
replace `j'=`j'/100;
};
append using r55_8`sector';
save r55_8`sector', replace;

***other stuff is own production, gifts, and pds purchases***;
clear;
infix str stuff 1-7
region 8-10 subround 11 subsample 12 str stuff2 13-17
fsu 18-22 visit 23 segment 24 stuff3 25 substratum 26
hhno 27-28 level 29-30 stuff4 31-32
item 33-35
quant7 36-43 value7 44-51
quant 52-59 value 60-67
str stuff5 68-126
using D126`sector'`k'.dat;
drop stuff*;
keep if level==9;
foreach j in quant7 value7 quant value{;
replace `j'=`j'/100;
};
append using r55_9`sector';
save r55_9`sector', replace;

clear;
infix str stuff 1-7
region 8-10 subround 11 subsample 12 str stuff2 13-17
fsu 18-22 visit 23 segment 24 stuff3 25 substratum 26
hhno 27-28 level 29-30 stuff4 31-32
item 33-35
quant 36-43 value 44-51
str stuff5 52-126
using D126`sector'`k'.dat;
drop stuff*;
keep if level==10;
foreach j in quant value{;
replace `j'=`j'/100;
};
append using r55_10`sector';
save r55_10`sector', replace;

clear;
infix str stuff 1-7
region 8-10 subround 11 subsample 12 str stuff2 13-17
fsu 18-22 visit 23 segment 24 stuff3 25 substratum 26
hhno 27-28 level 29-30 stuff4 31-32
item 33-35 type 36
quantpds 37-44 valuepds 45-52
quantother 53-60 valueother 61-68
str stuff5 69-126
using D126`sector'`k'.dat;
drop stuff*;
keep if level==11;
foreach j in quantpds valuepds quantother valueother{;
replace `j'=`j'/100;
};
append using r55_11`sector';
save r55_11`sector', replace;

clear;
infix str stuff 1-7
region 8-10 subround 11 subsample 12 str stuff2 13-17
fsu 18-22 visit 23 segment 24 stuff3 25 substratum 26
hhno 27-28 level 29-30 
blockcode 31-32 item 33-35 
quantrec 36-43 valuerec 44-51
quantggive 52-59 valueggive 60-67
quantgrec 68-75 valuegrec 76-81
str stuff5 82-126
using D126`sector'`k'.dat;
drop stuff*;
keep if level==13;
foreach j in quantrec valuerec
quantggive valueggive
quantgrec valuegrec{;
replace `j'=`j'/100;
};
append using r55_13`sector';
save r55_13`sector', replace;
};
};



clear;
use r55_4r;
gen sector=1;
append using r55_4u;
replace sector=2 if sector==.;
replace item=item-100;
keep sector region subround subsample fsu segment substratum hhno item value quant source;
save temp, replace;

clear;
use r55_5r;
gen sector=1;
append using r55_5u;
replace sector=2 if sector==.;
replace item=item-100;
keep sector region subround subsample fsu segment substratum hhno item value quant source;
append using temp;
save temp, replace;

clear;
use r55_6r;
gen sector=1;
append using r55_6u;
replace sector=2 if sector==.;
replace item=item-100;
replace value=value/12;
replace quant=quant/12;
keep sector region subround subsample fsu segment substratum hhno item value quant;
append using temp;
save temp, replace;

clear;
use r55_7r;
gen sector=1;
append using r55_7u;
replace sector=2 if sector==.;
replace item=item-100;
replace value=value/12 if item<320;
keep sector region subround subsample fsu segment substratum hhno item value;
append using temp;
save temp, replace;

clear;
use r55_8r;
gen sector=1;
append using r55_8u;
replace sector=2 if sector==.;
replace item=item-100;
replace firstquant=0 if firstquant==.;
replace secondquant=0 if secondquant==.;
gen quant=firstquant+secondquant;
replace value=0 if value==.;
replace secondvalue=0 if secondvalue==.;
replace value=value+secondvalue;
replace quant=quant/12;
replace value=value/12;

keep sector region subround subsample fsu segment substratum hhno item quant value;
append using temp;

replace quant=. if quant==0;
drop if item==29;
drop if item==59;
drop if item==69;
drop if item==79;
drop if item==89;
drop if item==129;
drop if item==149;
drop if item==159;
drop if item==169;
forvalues j=189(10)429{;
drop if item==`j';
};

*439 - imputed rent, urban only;
forvalues j=449(10)559{;
drop if item==`j';
};

drop if item<1;
drop if item>559;
gen ssstratum=1;
save round55_cedit, replace;



*************************************************;
************************61st round****************;
cd "`rootdir'Round61\";


clear;
save round61_chh1, emptyok replace;
save round61_chh2, emptyok replace;
save round61_chh3, emptyok replace;
save round61_cpers, emptyok replace;

forvalues j=1(1)8{;

clear;
infix str blank 1-3 fsu 4-8 round 9-10 sch 11-13
sample 14 sector 15 region 16-18 district 19-20
stratum 21-22 ssstratum 23-24 subround 25 subsample 26
fodsubregion 27-30 segment 31 substratum 32 hhno 33-34 level 35-36
str filler 37-46 date 47-52 str filler2 53-61
enoughfood 62 
jan 63-64 feb 65-66 mar 67-68 apr 69-70
may 71-72 jun 73-74 jul 75-76 aug 77-78 
sep 79-80 oct 81-82 nov 83-84 obtained 85
str blank2 86-126 nss 127-129 nsc 130-132 mult 133-142
using RMAH`j'C01.txt;
capture: drop filler* blank*;
keep if level==1;
append using round61_chh1;
save round61_chh1, replace;

clear;
infix str blank 1-3 fsu 4-8 round 9-10 sch 11-13
sample 14 sector 15 region 16-18 district 19-20
stratum 21-22 ssstratum 23-24 subround 25 subsample 26
fodsubregion 27-30 segment 31 substratum 32 hhno 33-34 level 35-36
str filler 37-41
hhsize 42-43 nic 44-48 nco 49-51 htype 52 religion 53 hgroup 54
ownland 55 typeland 56 landowned 57-65 landin 66-74 landneither 75-83
landout 84-92 landpos 93-101 cultpos 102-110 irrigated 111-119 
str stuff 120-126 nss 127-129 nsc 130-132 mult 133-142
using RMAH`j'C01.txt;
capture: drop stuff* filler*;
keep if level==2;
append using round61_chh2;
save round61_chh2, replace;

clear;
infix str blank 1-3 fsu 4-8 round 9-10 sch 11-13
sample 14 sector 15 region 16-18 district 19-20
stratum 21-22 ssstratum 23-24 subround 25 subsample 26
fodsubregion 27-30 segment 31 substratum 32 hhno 33-34 level 35-36
str filler 37-41
dwelling 42 cook 43-44 light 45 salary 46
ration 47 typeration 48 ben1 49 ben2 50 ben3 51 ben4 52
ceremony 53 mealsguests 54-57 mpce30 58-65 mpce365 66-73
str stuff 74-126 nss 127-129 nsc 130-132 mult 133-142
using RMAH`j'C01.txt;
capture: drop stuff* filler* blank*;
keep if level==3;
append using round61_chh3;
save round61_chh3, replace;

*consumption person file;
clear;
infix str blank 1-3 fsu 4-8 round 9-10 sch 11-13
sample 14 sector 15 region 16-18 district 19-20
stratum 21-22 ssstratum 23-24 subround 25 subsample 26
fodsubregion 27-30 segment 31 substratum 32 hhno 33-34 level 35-36
str filler 37-39 
relhh 42 sex 43 age 44-46 mstatus 47 generaled 48-49
daysaway 50-51 mealsday 52 mealsfree 53-54 mealsemp 55-56
mealsother 57-58 mealspay 59-60 mealshome 61-62 str blank2 63-126 nss 127-129 nsc 130-132 mult 133-142
using RMAH`j'C01.txt;
capture: drop filler* blank*;
keep if level==4;
append using round61_cpers;
save round61_cpers, replace;
};


clear;
use round61_chh1;
sort sector region subround fsu substratum subsample segment hhno;
save temp, replace;
clear;
use round61_chh2;
sort sector region subround fsu substratum subsample segment hhno;
merge sector region subround fsu substratum subsample segment hhno using temp;
tab _merge;
drop _merge;
sort sector region subround fsu substratum subsample segment hhno;
save temp, replace;
clear;
use round61_chh3;
sort sector region subround fsu substratum subsample segment hhno;
merge sector region subround fsu substratum subsample segment hhno using temp;
tab _merge;
drop _merge;
save round61_chh, replace;


*******Levels 4 and up -- Consumption data***************;
clear;
forvalues j=5(1)9{;
save r61_`j', emptyok replace;
};


forvalues j=1(1)8{;

clear;
infix str stuff 1-3 fsu 4-8 str stuff2 9-13
sample 14 sector 15 region 16-18 district 19-20
stratum 21-22 ssstratum 23-24 subround 25 subsample 26
fodsubregion 27-30 segment 31 substratum 32 hhno 33-34 level 35-36 stuff3 37-38
item 39-41
homequant 42-50 homevalue 51-58
quant 59-67 value 68-75 source 76
str stuff4 77-126
using RMAH`j'C01.txt;
keep if level==5;
drop stuff*;
foreach k in value homevalue{;
replace `k'=`k'/100;
};
foreach k in quant homequant{;
replace `k'=`k'/1000;
};



append using r61_5;
save r61_5, replace;

clear;
infix str stuff 1-3 fsu 4-8 str stuff2 9-13
sample 14 sector 15 region 16-18 district 19-20
stratum 21-22 ssstratum 23-24 subround 25 subsample 26
fodsubregion 27-30 segment 31 substratum 32 hhno 33-34 level 35-36
stuff3 37-38 item 39-41
quant30 42-50 value30 51-58
quant365 59-67 value365 68-75
str stuff4 76-126
using RMAH`j'C01.txt;
keep if level==6;
drop stuff*;
foreach k in value30 value365{;
replace `k'=`k'/100;
};
foreach k in quant30 quant365{;
replace `k'=`k'/1000 if item>=360 & item<=387;
};
append using r61_6;
save r61_6, replace;

clear;
infix str stuff 1-3 fsu 4-8 str stuff2 9-13
sample 14 sector 15 region 16-18 district 19-20
stratum 21-22 ssstratum 23-24 subround 25 subsample 26
fodsubregion 27-30 segment 31 substratum 32 hhno 33-34 level 35-36
stuff3 37-38 item 39-41
value30 42-49 value365 50-57
str stuff4 58-126
using RMAH`j'C01.txt;
keep if level==7;
drop stuff*;
foreach k in value30 value365{;
replace `k'=`k'/100;
};
append using r61_7;
save r61_7, replace;

clear;
infix str stuff 1-3 fsu 4-8 str stuff2 9-13
sample 14 sector 15 region 16-18 district 19-20
stratum 21-22 ssstratum 23-24 subround 25 subsample 26
fodsubregion 27-30 segment 31 substratum 32 hhno 33-34 level 35-36
stuff3 37-38 item 39-41
value 42-49
str stuff4 50-126
using RMAH`j'C01.txt;
keep if level==8;
drop stuff*;
foreach k in value{;
replace `k'=`k'/100;
};
append using r61_8;
save r61_8, replace;

clear;
infix str stuff 1-3 fsu 4-8 str stuff2 9-13
sample 14 sector 15 region 16-18 district 19-20
stratum 21-22 ssstratum 23-24 subround 25 subsample 26
fodsubregion 27-30 segment 31 substratum 32 hhno 33-34 level 35-36
stuff3 37-38 item 39-41
possess 42 
firstvalue30 43-50 repairvalue30 51-58
secondvalue30 59-66 value30 67-74
firstquant365 75-77
hired 78
firstvalue365 79-86 repairvalue365 87-94
secondquant365 95-97 secondvalue365 98-105
value365 106-113 str stuff4 114-126
using RMAH`j'C01.txt;
keep if level==9;
drop stuff*;
append using r61_9;
save r61_9, replace;

};


clear;
use r61_5;
replace item=item-100;
keep sector region subround subsample fsu substratum segment hhno item quant value homevalue homequant;
save temp, replace;

clear;
use r61_6;
replace item=item-100;
gen quant=quant365/12;
gen value=value365/12;
keep sector region subround subsample fsu substratum segment hhno item quant value;
append using temp;
save temp, replace;

clear;
use r61_7;
replace item=item-100;
gen value=value365/12;
keep sector region subround subsample fsu substratum segment hhno item value;
append using temp;
save temp, replace;

clear;
use r61_8;
replace item=item-100;
keep sector region subround subsample fsu substratum segment hhno item value;
append using temp;
save temp, replace;

clear;
use r61_9;
replace item=item-100;
replace firstquant365=0 if firstquant365==.;
replace secondquant365=0 if secondquant365==.;
gen quant=firstquant365+secondquant365;
gen value=value365;
replace quant=quant/12;
replace value=value/12;
keep sector region subround subsample fsu substratum segment hhno item quant value;
append using temp;

replace quant=. if quant==0;
drop if item==29;
drop if item==59;
drop if item==69;
drop if item==79;
drop if item==89;
drop if item==129;
drop if item==149;
drop if item==159;
drop if item==169;
forvalues j=189(10)429{;
drop if item==`j';
};

forvalues j=449(10)559{;
drop if item==`j';
};

drop if item<1;
drop if item>559;
save round61_cedit, replace;
 

 
 
*************************************************;
***** ************66th round*********************;
 ****Note that there are now two types of households, depending on the reporting period for consumption;
 *****Type 1 is the 30 day reporting period for everything which is what I use for comparability with earlier rounds

**********Type 1********
cd "`rootdir'round66\"
clear

save round661_chh1, emptyok replace
save round661_chh2, emptyok replace
save round661_chh3, emptyok replace
save round661_cpers, emptyok replace

forvalues j=1(1)10{

clear
infix str blank 1-3 fsu 4-8 round 9-10 sch 11-13 sample 14 sector 15 region 16-18 district 19-20 stratum 21-22 ssstratum 23 type 24 subround 25 subsample 26 fodsubregion 27-30 segment 31 substratum 32 hhno 33-34 level 35-36 str filler 37-46 date 47-52 str filler2 53-63 enoughfood 64 jan 65-66 feb 67-68 mar 69-70 apr 71-72 may 73-74 jun 75-76 jul 77-78 aug 79-80 sep 81-82 oct 83-84 nov 85-86 obtained 87 str blank2 88-126 nss 127-129 nsc 130-132 mult 133-142 using LVL66S011.0`j'.txt
capture: drop filler* blank*
keep if level==1
append using round661_chh1
save round661_chh1, replace

clear
infix str blank 1-3 fsu 4-8 round 9-10 sch 11-13 sample 14 sector 15 region 16-18 district 19-20 stratum 21-22 ssstratum 23 type 24 subround 25 subsample 26 fodsubregion 27-30 segment 31 substratum 32 hhno 33-34 level 35-36 str filler 37-41 hhsize 42-43 nic 44-48 nco 49-51 htype 52 religion 53 hgroup 54 ownland 55 typeland 56 landowned 57-64 landin 65-72 landneither 73-80 landout 81-88 landpos 89-96 cultpos 97-104 irrigated 105-112 str stuff 113-126 nss 127-129 nsc 130-132 mult 133-142 using LVL66S011.0`j'.txt
capture: drop stuff* filler*
keep if level==2
append using round661_chh2
save round661_chh2, replace

clear
infix str blank 1-3 fsu 4-8 round 9-10 sch 11-13 sample 14 sector 15 region 16-18 district 19-20 stratum 21-22 ssstratum 23 type 24 subround 25 subsample 26 fodsubregion 27-30 segment 31 substratum 32 hhno 33-34 level 35-36 str filler 37-41 cook 42-43 light 44 dwelling 45 salary 46 ceremony 47 mealsguests 48-51 internet 52 mpce 53-60  str stuff 61-126 nss 127-129 nsc 130-132 mult 133-142 using LVL66S011.0`j'.txt
capture: drop stuff* filler* blank*
keep if level==3
append using round661_chh3
save round661_chh3, replace
*Note: There are fewer household characteristics in this round. (Missing monthly expenditure, stuff about ration cards, whether they are a beneficiary of different support programs, and more)

*consumption person file
clear
infix str blank 1-3 fsu 4-8 round 9-10 sch 11-13 sample 14 sector 15 region 16-18 district 19-20 stratum 21-22 ssstratum 23 type 24 subround 25 subsample 26 fodsubregion 27-30 segment 31 substratum 32 hhno 33-34 level 35-36 str filler 37-39 persno 40-41 relhh 42 sex 43 age 44-46 mstatus 47 generaled 48-49 daysaway 50-51 mealsday 52 mealsfree 53-54 mealsemp 55-56 mealsother 57-58 mealspay 59-60 mealshome 61-62 str blank2 63-126 nss 127-129 nsc 130-132 mult 133-142 using LVL66S011.0`j'.txt
capture: drop filler* blank*
keep if level==4
append using round661_cpers
save round661_cpers, replace
}


clear
use round661_chh1
sort sector region subround fsu subsample segment substratum hhno
save tempH, replace
clear
use round661_chh2
sort sector region subround fsu subsample segment substratum hhno
merge sector region subround fsu subsample segment substratum hhno using tempH
tab _merge
drop _merge
sort sector region subround fsu subsample segment substratum hhno hhno
save tempH, replace
clear
use round661_chh3
sort sector region subround fsu subsample segment substratum hhno hhno
merge sector region subround fsu subsample segment substratum hhno using tempH
tab _merge
drop _merge
cap: gen ssstratum=1
save round661_chh, replace


****Type 1 Consumption data********

# delimit ;
forvalues j=5(1)9{;
save r66_`j', emptyok replace;
};


forvalues i=1(1)10{;

clear;
infix str stuff 1-3 fsu 4-8 str stuff2 9-13 sample 14 sector 15 region 16-18 district 19-20 stratum 21-22 ssstratum 23 type 24 subround 25 subsample 26 fodsubregion 27-30 segment 31 substratum 32 hhno 33-34 level 35-36 stuff3 37-38 item 39-41 homequant 42-50 homevalue 51-58 quant 59-67 value 68-75 source 76 str stuff4 77-126 using LVL66S011.0`i'.txt;
keep if level==5;
drop stuff*;
foreach k in quant homequant{;
replace `k'=`k'/1000;
};
append using r66_5;
save r66_5, replace;

clear;
infix str stuff 1-3 fsu 4-8 str stuff2 9-13 sample 14 sector 15 region 16-18 district 19-20 stratum 21-22 ssstratum 23 type 24 subround 25 subsample 26 fodsubregion 27-30 segment 31 substratum 32 hhno 33-34 level 35-36 stuff3 37-38 item 39-41
quant30 42-50 value30 51-58 quant365 59-67 value365 68-75
str stuff4 76-126
using LVL66S011.0`i'.txt;
keep if level==6;
drop stuff*;
foreach k in quant30 quant365{;
replace `k'=`k'/1000 if item>=360 & item<=387;
};
append using r66_6;
save r66_6, replace;

clear;
infix str stuff 1-3 fsu 4-8 str stuff2 9-13 sample 14 sector 15 region 16-18 district 19-20 stratum 21-22 ssstratum 23 type 24 subround 25 subsample 26 fodsubregion 27-30 segment 31 substratum 32 hhno 33-34 level 35-36 stuff3 37-38 item 39-41
value30 42-49 value365 50-57
str stuff4 58-126
using LVL66S011.0`i'.txt;
keep if level==7;
drop stuff*;
append using r66_7;
save r66_7, replace;

clear;
infix str stuff 1-3 fsu 4-8 str stuff2 9-13 sample 14 sector 15 region 16-18 district 19-20 stratum 21-22 ssstratum 23 type 24 subround 25 subsample 26 fodsubregion 27-30 segment 31 substratum 32 hhno 33-34 level 35-36 stuff3 37-38 item 39-41
value 42-49
str stuff4 50-126
using LVL66S011.0`i'.txt;
keep if level==8;
drop stuff*;
append using r66_8;
save r66_8, replace;

clear;
infix str stuff 1-3 fsu 4-8 str stuff2 9-13 sample 14 sector 15 region 16-18 district 19-20 stratum 21-22 ssstratum 23 type 24 subround 25 subsample 26 fodsubregion 27-30 segment 31 substratum 32 hhno 33-34 level 35-36 stuff3 37-38 item 39-41
possess 42 
firstquant30 43-45
hired30 46
firstvalue30 47-54 repairvalue30 55-62
secondvalue30 63-70
value30 71-78
firstquant365 79-81
hired 82
firstvalue365 83-90 repairvalue365 91-98
secondquant365 99-101 secondvalue365 102-109
value365 110-117
str stuff4 82-126
using LVL66S011.0`i'.txt;
keep if level==9;
drop stuff*;
append using r66_9;
save r66_9, replace;

};


clear;
use r66_5;
replace item=item-100;
keep sector region subround fsu subsample segment substratum hhno item quant value homequant homevalue;
save temp, replace;

clear;
use r66_6;
replace item=item-100;
gen quant=quant365/12;
gen value=value365/12;
keep sector region subround fsu subsample segment substratum hhno item quant value;
append using temp;
save temp, replace;

clear;
use r66_7;
replace item=item-100;
gen value=value365/12;
keep sector region subround fsu subsample segment substratum hhno item value;
append using temp;
save temp, replace;

clear;
use r66_8;
replace item=item-100;
keep sector region subround fsu subsample segment substratum hhno item value;
append using temp;
save temp, replace;

clear;
use r66_9;
replace item=item-100;
replace firstquant365=0 if firstquant365==.;
replace secondquant365=0 if secondquant365==.;
gen quant=firstquant365+secondquant365;
gen value=value365;
replace quant=quant/12;
replace value=value/12;
keep sector region subround fsu subsample segment substratum hhno item quant value;
append using temp;

replace quant=. if quant==0;
drop if item==29;
drop if item==59;
drop if item==69;
drop if item==79;
drop if item==99;
drop if item==79;
drop if item==109;
drop if item==149;
drop if item==169;
drop if item==179;
forvalues j=189(10)429{;
drop if item==`j';
};

*439 - imputed rent, urban only;
forvalues j=449(10)559{;
drop if item==`j';
};

drop if item<1;
drop if item>559;
gen ssstratum=1;
save round661_cedit, replace;




